#!/usr/bin/perl

sub min_n { return (sort {$a<=>$b} grep {defined} @_)[0] }

open MATRIX, "matrix1.txt";

my @rows = map { [split /,/] } <MATRIX>;
my $nrows =  $#rows;

print "$nrows\n";

for (my $i = $nrows; $i >= 0; $i--) {
    for (my $j = $nrows; $j >= 0; $j--) {
	$t = min_n($rows[$i+1][$j], $rows[$i][$j+1]);
        $rows[$i][$j] += $t;
	print "$t ";
    }
}
print "Answer to PE81 = $rows[0][0]\n";

